package com.ruoyi.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;

import javax.annotation.Resource;
import java.util.Arrays;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.business.domain.TaskAnnex;
import com.ruoyi.business.service.ITaskAnnexService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 任务附件Controller
 *
 * @author Eric
 * @date 2024-03-20
 */
@RestController
@RequestMapping("/business/annex")
public class TaskAnnexController extends BaseController {
    @Resource
    private ITaskAnnexService taskAnnexService;

    /**
     * 查询任务附件列表
     */
    @PreAuthorize("@ss.hasPermi('business:annex:list')")
    @GetMapping("/list")
    public TableDataInfo list(TaskAnnex taskAnnex) {
        startPage();
        List<TaskAnnex> list = taskAnnexService.list(Wrappers.lambdaQuery(TaskAnnex. class).
        setEntity( taskAnnex));
        return getDataTable(list);
    }

    /**
     * 导出任务附件列表
     */
    @PreAuthorize("@ss.hasPermi('business:annex:export')")
    @Log(title = "任务附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TaskAnnex taskAnnex) {
        List<TaskAnnex> list = taskAnnexService.list(Wrappers.lambdaQuery(TaskAnnex. class).
        setEntity( taskAnnex));
        ExcelUtil<TaskAnnex> util = new ExcelUtil<TaskAnnex>(TaskAnnex. class);
        util.exportExcel(response, list, "任务附件数据");
    }

    /**
     * 获取任务附件详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:annex:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(taskAnnexService.getById(id));
    }

    /**
     * 新增任务附件
     */
    @PreAuthorize("@ss.hasPermi('business:annex:add')")
    @Log(title = "任务附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TaskAnnex taskAnnex) {
        return toAjax(taskAnnexService.save(taskAnnex));
    }

    /**
     * 修改任务附件
     */
    @PreAuthorize("@ss.hasPermi('business:annex:edit')")
    @Log(title = "任务附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TaskAnnex taskAnnex) {
        return toAjax(taskAnnexService.updateById(taskAnnex));
    }

    /**
     * 删除任务附件
     */
    @PreAuthorize("@ss.hasPermi('business:annex:remove')")
    @Log(title = "任务附件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(taskAnnexService.removeBatchByIds(Arrays.asList(ids)));
    }
}
